//author:jxx
//此处是对表单的方法，组件，权限操作按钮等进行任意扩展(方法扩展可参照SellOrder.js)
import gridFooter from "./volumn/mall_volumn_item.vue";
let extension = {
    components: {//动态扩充组件或组件路径
        //表单header、content、footer对应位置扩充的组件
        gridHeader:()=>//{ template: "<div>扩展组xx件</div>" },
        import ("./volumn/volumngridHeader.vue"),
        gridBody: '',
        gridFooter: gridFooter,
        //弹出框(修改、编辑、查看)header、content、footer对应位置扩充的组件
        modelHeader: '',
        modelBody: '',
        modelFooter: ''
    },
    buttons: {view: [], box:[],  detail:[]},//扩展的按钮
    methods: {//事件扩展
        onInited() {
            //this.height = this.height-400;
            this.detailOptions.height = this.detailOptions.height - 200;
          },
       onInit() {
        
        this.maxBtnLength = 5;
        this.boxOptions.height = 530;
        this.columns.push({
            title: '操作',
            fixed: 'right',
            width: 90,
            render: (h, { row, column, index }) => {
                return h(
                    "div", { style: {} }, [
                        h(
                            "a", {
                            props: {},
                            style: {},
                            on: {
                              click: (e) => {
                               // e.stopPropagation()
                               // this.linkData(row);
                                this.modelOpenAfter();
                                this.$refs.gridHeader.open(row); // 生成0~5的随机整数
                              }
                            }
                          },
                            "制券    "
                          ),
                          h(
                            "a", {
                                props: {},
                                style: {},
                                on: {
                                    click: (e) => {
                                        this.linkData(row);
                                    }
                                }
                            },
                            "编辑"
                        ),

                        
                    ])
            }
        })
        
        var effectiveStartDate = this.getFormOption('effectiveStartDate');
            var effectiveEndDate = this.getFormOption('effectiveEndDate');
            effectiveStartDate.onChange = (val, item) => {   
              effectiveEndDate.min=val;
            }
            effectiveEndDate.onChange = (val, item) => {    
              effectiveStartDate.max=val;
            }
       },
       
       getFormOption(field) {
        let option;
        this.editFormOptions.forEach(x => {
            x.forEach(item => {
                if (item.field == field) {
                    option = item;
                }
            })
        })
        return option;
        },
       rowClick({ row, column, event }) { //查询界面table点击行选中当前行
        //console.log(row,column,event);
        let where = {wheres:[
            {"name":"volumeID","value":row.id,displayType:"text"},
           ],
           sort:"createDate",  //orderNo以前是这个
           order: "desc"};
          this.$refs.table.$refs.table.toggleRowSelection(row);
          this.$refs.gridFooter.$refs.tableList.load(where)
         return true;
       },
       searchAfter(rows) {
        //页面加载或者刷新数据后直接显示第一行的明细
        if (rows.length) {
          let where = {wheres:[
            {"name":"volumeID","value":rows[0].id,displayType:"text"},
          //设置为like模糊查询
            ],
            sort:"createDate",
            order: "desc"};
          // this.$nextTick(() => {
          this.$refs.gridFooter.$refs.tableList.load(where)
          // })
         }else{
          //没有数据时，清空明细数据
          this.$refs.gridFooter.$refs.tableList.reset()
        }
        return true;
      },
       modelOpenAfter() {
        //获取当前弹出框是新建还是编辑状态
        let isEDIT = this.currentAction == this.const.EDIT;
        this.editFormOptions.forEach(item =>{
            item.forEach(x =>{
                //如果是编辑，库存设置只读
                if(x.field == "quantity"){
                    this.$set(x,"disabled",isEDIT)
                }
                if(x.field == "isUnlimitedQuantity"){
                    this.$set(x,"disabled",isEDIT)
                }
            })
        })
        var selectOption = this.getFormOption('volumeDescription');  
        var quantity = this.getFormOption('quantity');
        
        if(!isEDIT) {
            selectOption.onInput = (val) => {    
            this.editFormFields.volumeCode =this.base.chineseToPinYin(val);
            }
            this.$set(quantity, "disabled", true)
            this.$set(quantity, "required", false)
            this.editFormFields.quantity='';
            
        } 
       // if(!isEDIT){
            quantity.onInput = (val)=>{
                this.editFormFields.volumeCode = this.base.chineseToPinYin(val);
            }
       // }
        var Code = this.getFormOption('volumeCode');
        this.$set(Code, "disabled", true)
        var isSupportoffline = this.getFormOption('isSupportoffline');
        var offlineCode = this.getFormOption('offlineCode');
        isSupportoffline.onChange = (val, item) => {    
        if(val==1){
                this.$set(offlineCode, "disabled", false)
                this.$set(offlineCode, "required", true)
                this.editFormFields.offlineCode='';
            }else{
                this.$set(offlineCode, "disabled", true)
                this.$set(offlineCode, "required", false)
            }
        }
        var isCredit = this.getFormOption('isUnlimitedQuantity');
        isCredit.onChange = (val, item) => {    
            //console.log(val) 
            if(val==1){
                this.$set(quantity, "disabled", true)
                this.$set(quantity, "required", false)
                this.editFormFields.quantity="";
            }else{
                this.$set(quantity, "disabled", false)
                this.$set(quantity, "required", true)
            }
        }
        var isSupportonline = this.getFormOption('isSupportonline');
        var onlineCode = this.getFormOption('onlineCode');
        isSupportonline.onChange = (val,item)=>{
            if(val==1){
                this.editFormFields.onlineCode='';
                this.$set(onlineCode,"disabled",false)
                this.$set(onlineCode,"required",true)
                
            }else{
                this.$set(onlineCode,"disabled",true)
                this.$set(onlineCode,"required",false)
            }
        }
        if(isEDIT){
            console.log(this.editFormFields.isSupportonline,this.editFormFields.isSupportoffline,this.editFormFields.isUnlimitedQuantity)
            if(this.editFormFields.isSupportonline==1){   //线上
                this.editFormFields.onlineCode='';
                this.$set(onlineCode,"disabled",false)
                this.$set(onlineCode,"required",true)
            }else{
                this.$set(onlineCode,"disabled",true)
                this.$set(onlineCode,"required",false)
                this.editFormFields.onlineCode='';
            }   
            if(this.editFormFields.isSupportoffline==1){    //线下
                this.$set(offlineCode, "disabled", false)
                this.$set(offlineCode, "required", true)
                this.editFormFields.offlineCode='';
                
            }else{
                this.$set(offlineCode, "disabled", true)
                this.$set(offlineCode, "required", false)
                
            }
            // if(this.editFormFields.IsUnlimitedQuantity==1){   //库存
            //     this.$set(quantity,"disabled",true)
            //     this.$set(quantity,"required",false)
            //     this.editFormFields.quantity='';
            // }else{
            //     this.$set(quantity,"disabled",false)
            //     this.$set(quantity,"required",true)
            // }
        }
        
       }
    },
};
export default extension;